﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PresentationLayer
{
    public partial class DeptHomePage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                #region Check if user exists and has permission to view this page
                if (Session["UserLoggedIn"] != null)
                {
                    List<string> list = Session["UserLoggedIn"] as List<string>;
                    if (list[0].Equals("validuser"))
                    {
                        int roleId = Convert.ToInt32(list[6]);
                        if (roleId < 0 || roleId > 4)
                        {
                            Response.Redirect("/AccessDenied.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("/Login.aspx");
                    }
                }
                else
                {
                    Response.Redirect("/Login.aspx");
                }
                #endregion

                List<string> deptList = Session["UserLoggedIn"] as List<string>;
                string employeeName = deptList[5];
                //string userRole = "";

                //HttpCookieCollection myCookieCollection = Request.Cookies;

                //for (int j = 0; j < myCookieCollection.Count; j++)
                //{
                //    HttpCookie myCookie = myCookieCollection[j];
                //    if (myCookie.Name.Equals("UsersRole"))
                //    {
                //        userRole = myCookie.Values.Get("role");
                //    }
                //}
                lblEmployeeName.Text = employeeName;
            }
            catch (Exception ex)
            {
            }
        }
    }
}